package com.wy.business.market.home.actions;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ExceptionMapping;
import org.apache.struts2.convention.annotation.ExceptionMappings;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

import com.wy.business.market.home.services.CardManageService;
import com.wy.framework.actions.AbstractBaseAction;
import com.wy.framework.dao.ErrorSqlException;
import com.wy.framework.exceptions.ServiceException;

/**
 * 
 * 项目名称：openportal
 * 类名称：CardAction
 * 类描述：卡片管理
 * 创建人：高振泰
 * 创建时间：2016-1-5 下午4:07:10
 * 修改人：
 * 修改时间：2016-1-5 下午4:07:10
 * 版本信息：@version 1.0
 * Copyright (c) 2016万雍科技（上海）有限公司-版权所有  
 * 修改备注：
 * @version
 */
@ParentPackage("json")
@Namespace("/home/card")
@ExceptionMappings({ @ExceptionMapping(exception = "java.lange.RuntimeException", result = "error") })
public class CardAction extends AbstractBaseAction {
	private static final long serialVersionUID = 1L;
	private static Log logger = LogFactory.getLog(CardAction.class);
     
	@Autowired
	private CardManageService cardManageService;
	private List<Map> rows;
	
	@SuppressWarnings("unchecked") 
	@Action(value = "show", results = { @Result(name = "success", location = "/jsps/apiEncrypt.jsp") })
	public String show()throws ServiceException{
//		String userId = ServletActionContext.getRequest().getParameter("userId");
//		rows = new ArrayList();
//		
//		Map m = new HashMap();
//		m.put("title", "卡片1");
//		m.put("class", "0");
//		m.put("picUrl", "http://vanyapp.com:8765/upload/668a4b01-d45c-4b4c-be36-1a04e521b627.jpg");
//		m.put("picTitle", "小太阳");
//		m.put("picDetailUrl", "http://baidu.com");
//		m.put("moreUrl", "");
//		m.put("topFlg", "0");
//		m.put("source", "http://baidu.com");
//		m.put("sort", "2");
//		return SUCCESS;
		try {
			rows = cardManageService.show();
		} catch (ErrorSqlException e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	
	@SuppressWarnings("unchecked") 
	@Action(value = "list", 
			interceptorRefs = { @InterceptorRef("sessionStack") }, 
			results = { @Result(name = "success", type = "json", params = {
			"noCache", "true", "contentType", "text/html", "ignoreHierarchy",
			"false"}) })
	public String list() throws ServiceException{
		String userId = ServletActionContext.getRequest().getParameter("userId");
		rows = new ArrayList();
		
		Map m = new HashMap();
		m.put("title", "学校介绍");
		m.put("content", "就是一个字,好");
		m.put("class", "0");
		m.put("iconName", "123");
		m.put("belongFlg", "0");
		m.put("sort", "1");
		rows.add(m);
		return SUCCESS;
	}
	
	@SuppressWarnings("unchecked") 
	@Action(value = "detail", 
			interceptorRefs = { @InterceptorRef("sessionStack") }, 
			results = { @Result(name = "success", type = "json", params = {
			"noCache", "true", "contentType", "text/html", "ignoreHierarchy",
			"false"}) })
	public String detail()throws ServiceException{
		String cardId = ServletActionContext.getRequest().getParameter("cardId");
		rows = new ArrayList();
		Map m = new HashMap();
		m.put("title", "111");
		m.put("content", "22");
		m.put("addTotalCtn", "2011");
		m.put("examplePicUrl", "www.baidu.com");
		m.put("belongFlg", "0");
		return SUCCESS;
	}
	
	@SuppressWarnings("unchecked") 
	@Action(value = "add", 
			interceptorRefs = { @InterceptorRef("sessionStack") }, 
			results = { @Result(name = "success", type = "json", params = {
			"noCache", "true", "contentType", "text/html", "ignoreHierarchy",
			"false"}) })
	public String add()throws ServiceException{
		String userId = ServletActionContext.getRequest().getParameter("userId");	
		String cardId = ServletActionContext.getRequest().getParameter("cardId");	
		return SUCCESS;
	}
	
	@SuppressWarnings("unchecked") 
	@Action(value = "delete", 
			interceptorRefs = { @InterceptorRef("sessionStack") }, 
			results = { @Result(name = "success", type = "json", params = {
			"noCache", "true", "contentType", "text/html", "ignoreHierarchy",
			"false"}) })
	public String delete()throws ServiceException{
		String userId = ServletActionContext.getRequest().getParameter("userId");	
		String cardId = ServletActionContext.getRequest().getParameter("cardId");	
		return SUCCESS;
	}
	
	@SuppressWarnings("unchecked") 
	@Action(value = "toTop", 
			interceptorRefs = { @InterceptorRef("sessionStack") }, 
			results = { @Result(name = "success", type = "json", params = {
			"noCache", "true", "contentType", "text/html", "ignoreHierarchy",
			"false"}) })
	public String toTop()throws ServiceException{
		String userId = ServletActionContext.getRequest().getParameter("userId");	
		String cardId = ServletActionContext.getRequest().getParameter("cardId");	
		return SUCCESS;
	}

	public List<Map> getRows() {
		return rows;
	}
	

}
